package main

import (
	"fmt"
	"math"
	"util"
)

/*
8ms 100%
像是脑筋急转弯
正反面数字相同的卡，对应的数字不可能是结果
将所有正/反面包含这些数字的卡排除掉
从剩余卡中找正/反面数字最小的卡就是结果
*/
func flipgame(fronts []int, backs []int) int {
	set := make(map[int]bool)
	n := len(fronts)
	for i := 0; i < n; i++ {
		if fronts[i] == backs[i] {
			set[fronts[i]] = true
		}
	}
	res := math.MaxInt32
	for i := 0; i < n; i++ {
		if _, contains := set[fronts[i]]; !contains {
			res = util.Min(fronts[i], res)
		}
		if _, contains := set[backs[i]]; !contains {
			res = util.Min(backs[i], res)
		}
	}
	if res == math.MaxInt32 {
		res = 0
	}
	return res
}

func main() {
	fronts := []int{1, 2, 4, 4, 7}
	backs := []int{1, 3, 4, 1, 3}
	res := flipgame(fronts, backs)
	fmt.Println(res)
}
